package com.example.navigation.views


import android.content.Intent
import android.content.SharedPreferences
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.example.navigation.LoginActivity
import com.example.navigation.MainActivity
import com.example.navigation.SettingActivity
import com.example.navigation.api.login.LoginApi

/**
 * Created with IntelliJ IDEA.
 * @Author: Liao Run
 * @Date: 2024-06-13 10:01
 * @Description:
 **/
@Composable
fun MyPage(userInfo: LoginApi.UserInfo?, mainActivity: MainActivity, sharedPref: SharedPreferences) {
    Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
        Spacer(modifier = Modifier)
        IconButton(onClick = {
            mainActivity.startActivity(Intent(mainActivity, SettingActivity::class.java))
        }) {
            Icon(imageVector = Icons.Default.Settings, contentDescription = "设置界面")
        }
    }
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center,
        modifier = Modifier.fillMaxSize()
    ) {
        TextField(value = userInfo?.username ?: "", onValueChange = {}, label = {
            Text(text = "用户名")
        })


        Button(onClick = {
            with(sharedPref.edit()) {
                remove("user")
                commit()
            }
            mainActivity.startActivity(Intent(mainActivity, LoginActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
            mainActivity.finish()
        }) {
            Text(text = "退出登录")
        }
    }

}